#include "incomerecordlist.h"

IncomeRecordList::IncomeRecordList(){}

int IncomeRecordList::categorysize(){
    return incomeCategoryList.size();
}

QString IncomeRecordList::getcategory(int i){
    return incomeCategoryList[i];
}

void IncomeRecordList::operator=(IncomeRecordList copy){
    RCL = copy.getRecordList();
    incomeCategoryList = copy.getCategoryList();
}

void IncomeRecordList::addCategory(QString category){
    int i = 0;
    bool exists = false;
    // Check if the category exists before adding
    for(i = 0; i < this->incomeCategoryList.size(); i++){
        if(this->incomeCategoryList[i] == category){
            exists = true;
            break;
        }
    }
    if(!exists)
        this->incomeCategoryList.push_back(category);
}

void IncomeRecordList::removeCategory(QString category){
    int i = 0;
    // Do not need to check if category exists before removing.
    for(i = 0; i < incomeCategoryList.size(); i++){
        if(this->incomeCategoryList[i] == category){
            this->incomeCategoryList.erase((this->incomeCategoryList.begin() + i));
            break;
        }
    }
}

double IncomeRecordList::calculateIncome(){
    int i = 0;
    double income = 0;
    for(i = 0; i < this->RCL.size(); i ++)
        income += RCL[i].getamount();
    return income;
}

vector<QString> IncomeRecordList::getCategoryList(){
    return this->incomeCategoryList;
}

void IncomeRecordList::clearCategoryList(){
    this->incomeCategoryList.clear();
}

vector<QString> IncomeRecordList::incomeCategoryList;
